﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;

namespace SportingGoodsExhibitionSystem
{
    /// <summary>
    /// scheInfo.xaml 的交互逻辑
    /// </summary>
    public partial class scheInfo : Page
    {
        public scheInfo()
        {
            InitializeComponent();
        }
        string strCon = Properties.Resources.strCON;
        string stuNum;


        private void Button_Click(object sender, RoutedEventArgs e)
        {
            string dateStart;
            dateStart = textTimestart.Text+" "+stratHour.Text + "时" + stratMin.Text + "分";
            string dateEnd;
            dateEnd = textTimeEnd.Text + " " + textEndHour.Text + "时" + textEndMin.Text + "分";
            SqlConnection con = new SqlConnection(strCon);
            con.Open();
            SqlCommand cmd = new SqlCommand("insert into scheInfo(stunum,starttime,tranway,goplace,arriveplace,endtime) values(@id,@sttime,@tway,@gpla,@arpl,@etime)", con);
            cmd.Parameters.Add("@id", SqlDbType.Int, 10).Value = stuNum;
            cmd.Parameters.Add("@sttime", SqlDbType.VarChar, 50).Value = dateStart;
            cmd.Parameters.Add("@tway", SqlDbType.VarChar, 50).Value = textTran.Text;
            cmd.Parameters.Add("@gpla", SqlDbType.VarChar, 50).Value = textStartPlace.Text;
            cmd.Parameters.Add("@arpl", SqlDbType.VarChar, 50).Value = textEndPlace.Text;
            cmd.Parameters.Add("@etime", SqlDbType.VarChar, 50).Value = dateEnd;
            cmd.ExecuteNonQuery();
            
            con.Close();
            MessageBox.Show("填写完成");
        }

        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            SqlConnection con = new SqlConnection(strCon);
            con.Open();
            SqlCommand cmd = new SqlCommand("select * from studentInfo where studentStatus=@num", con);
            cmd.Parameters.Add("@num", SqlDbType.Int, 10).Value = 1;
            SqlDataAdapter read = new SqlDataAdapter(cmd);
            //DataTable dt = new DataTable();
            DataSet dataset = new DataSet();
            read.Fill(dataset);
            DataTable table = dataset.Tables[0];
            DataRowCollection rows = table.Rows;
            DataRow row = rows[0];
            stuNum = row["studentNumber"].ToString();
            con.Close();
        }

       
    }

    public class timeConver2 : IValueConverter
    {
        object IValueConverter.Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
                return DependencyProperty.UnsetValue;
            DateTime dt = (DateTime)value;
            return dt.ToString("yyyy年MM月dd日");
        }

        object IValueConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
